import {
    AddParams,
    AddRes,
    DeleteParams,
    DeleteRes,
    PauseParams,
    PauseRes,
    QueryRes,
    RescheduleParams, RescheduleRes, ResumeParams, ResumeRes, RunParams, RunRes
} from "@/api/batch/type.ts";
import request from "@/utils/request.ts";

/**
 * 添加定时任务
 * @param params
 */
export function addBatch(params: AddParams): Promise<AddRes> {
    return request.post(`/batch/admin/batch/add`, params);
}

/**
 * 删除任务
 * @param {object} params CronJobReq
 * @param {string} params.cron
 * @param {string} params.name
 * @param {string} params.group
 * @param {string} params.desc
 * @returns
 */
export function deleteBatch(params: DeleteParams|any): Promise<DeleteRes> {
    return request.delete(`/batch/admin/batch/delete`, params);
}

/**
 * 暂停任务
 * @param {object} params CronJobReq
 * @param {string} params.cron
 * @param {string} params.name
 * @param {string} params.group
 * @param {string} params.desc
 * @returns
 */
export function pause(params: PauseParams): Promise<PauseRes> {
    return request.post(`/batch/admin/batch/pause`, params);
}

/**
 * 查看所有任务
 * @returns
 */
export function query(): Promise<QueryRes> {
    return request.get(`/batch/admin/batch/query`);
}

/**
 * 更新任务
 * @param {object} params CronJobReq
 * @param {string} params.cron
 * @param {string} params.name
 * @param {string} params.group
 * @param {string} params.desc
 * @returns
 */
export function reschedule(params: RescheduleParams): Promise<RescheduleRes> {
    return request.post(`/batch/admin/batch/reschedule`, params);
}

/**
 * 重启任务
 * @param {object} params CronJobReq
 * @param {string} params.cron
 * @param {string} params.name
 * @param {string} params.group
 * @param {string} params.desc
 * @returns
 */
export function resume(params: ResumeParams): Promise<ResumeRes> {
    return request.post(`/batch/admin/batch/resume`, params);
}

/**
 * 手动执行任务
 * @param {object} params CronJobReq
 * @param {string} params.cron
 * @param {string} params.name
 * @param {string} params.group
 * @param {string} params.desc
 * @returns
 */
export function runBatch(params: RunParams): Promise<RunRes> {
    return request.post(`/batch/admin/batch/run`, params);
}